package si.yun.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import si.yun.common.ConstantEntity;
import si.yun.service.SyNavigation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: 导航栏service实现类
 * @Description: TODO
 * @Author: 李振海
 * @Date 2021/7/28 11:37
 */
@Service
public class SyNavigationImpl implements SyNavigation {

    @Autowired
    private si.yun.dao.SyMenuMapper SyMenuMapper;

    @Autowired
    private si.yun.dao.SyLoginRecordMapper SyLoginRecordMapper;

    @Autowired
    private si.yun.dao.SyDeptMapper SyDeptMapper;

    @Autowired
    private si.yun.dao.SyUserOrderMapper SyUserOrderMapper;

    /**
     * @Author : 李振海
     * @Date : 2021/7/28 11:56
     * @Param : []
     * @Return : java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     */
    @Override
    public List<Map<String, Object>> selNavigation() {
        List<Map<String, Object>> getNavigationFather=SyMenuMapper.selNavigationFather(null);
        for(Map<String, Object> i:getNavigationFather){
            int id = (int) i.get("menu_id");
            List<Map<String, Object>> navigationSon = selNavigationSon(id);
            if(navigationSon.size()==0){
                continue;
            }
            i.put("children",navigationSon);
        }
        return getNavigationFather;
    }

    /**
     * @Author : 李振海
     * @Date : 2021/7/28 12:40
     * @Param : [id]
     * @Return : java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     */
    public List<Map<String, Object>> selNavigationSon(int id) {
        List<Map<String, Object>> getNavigationFather=SyMenuMapper.selNavigationFather(id);
        for(Map<String, Object> i:getNavigationFather){
            int idSon = (int) i.get("menu_id");
            List<Map<String, Object>> navigationSon = SyMenuMapper.selNavigationFather(idSon);
            if(navigationSon.size()==0){
                continue;
            }
            i.put("children",navigationSon);

        }
        return getNavigationFather;
    }

    /**
     * @Author : 李振海
     * @Date : 2021/7/29 15:58
     * @Param : [id]
     * @Return : java.util.List<java.util.HashMap<java.lang.String,java.lang.Object>>
     */
    @Override
    public List<Map<String,Object>> selLoginLog(int id) {
        List<Map<String,Object>> selLoginLog=SyLoginRecordMapper.selLoginLog(id);
        String selLoginLogDept=SyDeptMapper.selLoginLogDept(id);
        selLoginLog.get(0).put("dept",selLoginLogDept);
        return selLoginLog;
    }

    /**
     * @Author : 李振海
     * @Date : 2021/7/29 18:51
     * @Param : [id]
     * @Return : java.util.List<java.util.HashMap<java.lang.String,java.lang.Object>>
     */
    @Override
    public  List<Map<String,Object>> selIndexOrderPrompt(String id) {
        List<Map<String,Object>> list=new ArrayList<>();
        Map<String,Object> map=new HashMap<>();

        int selIndexOrderPrompt2=SyUserOrderMapper.selIndexOrderPrompt(id,ConstantEntity.TWO );//2待付款
        map.put("selIndexOrderPrompt2",selIndexOrderPrompt2);
        int selIndexOrderPrompt3=SyUserOrderMapper.selIndexOrderPrompt(id,ConstantEntity.THREE);// 3已付款
        map.put("selIndexOrderPrompt3",selIndexOrderPrompt3);
        int selIndexOrderPrompt4=SyUserOrderMapper.selIndexOrderPrompt(id,ConstantEntity.FOUR);//4待发货
        map.put("selIndexOrderPrompt4",selIndexOrderPrompt4);
        int selIndexOrderPrompt5=SyUserOrderMapper.selIndexOrderPrompt(id,ConstantEntity.FIVE);//5已发货
        map.put("selIndexOrderPrompt5",selIndexOrderPrompt5);
        int selIndexOrderPrompt6=SyUserOrderMapper.selIndexOrderPrompt(id,ConstantEntity.SIX);//6已签收
        map.put("selIndexOrderPrompt6",selIndexOrderPrompt6);
        int selIndexOrderPrompt7=SyUserOrderMapper.selIndexOrderPrompt(id,ConstantEntity.SEVEN);//7退货申请
        map.put("selIndexOrderPrompt7",selIndexOrderPrompt7);
        int selIndexOrderPrompt8=SyUserOrderMapper.selIndexOrderPrompt(id,ConstantEntity.EIGHT);//8退货中
        map.put("selIndexOrderPrompt8",selIndexOrderPrompt8);
        int selIndexOrderPrompt9=SyUserOrderMapper.selIndexOrderPrompt(id,ConstantEntity.NINE);//9已退货
        map.put("selIndexOrderPrompt9",selIndexOrderPrompt9);
        int selIndexOrderPrompt10=SyUserOrderMapper.selIndexOrderPrompt(id,ConstantEntity.TEN);//10取消交易
        map.put("selIndexOrderPrompt10",selIndexOrderPrompt10);
        int i=selIndexOrderPrompt2+selIndexOrderPrompt4+selIndexOrderPrompt5+selIndexOrderPrompt6;

        map.put("sum",i);

        list.add(map);
        return list;
    }

    /**
     * @author: DZQ
     * @description: 登录日志的添加
     * @date: 2021/11/17 8:58
     * @return
     */
    @Override
    public int addLogin( String loginLocation, String loginIp,Integer mid) {
        int num=SyLoginRecordMapper.addLogin(loginLocation,loginIp,mid);
        return num;
    }
}
